package com.jxs.android.weiget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jxs.android.ges.R;

public class WorkLogEditItem extends LinearLayout {

	private EditText content, note;
	private TextView index;

	public WorkLogEditItem(Context context, int id) {
		super(context);
		init(context);
		index.setText(String.valueOf(id));

	}

	private void init(Context context) {
		LayoutInflater.from(context).inflate(R.layout.bu_work_log_edit_item, this);
		index = (TextView) findViewById(R.id.index);
		content = (EditText) findViewById(R.id.content);
		note = (EditText) findViewById(R.id.note);
	}

	public WorkLogEditItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkLogEditItem);
		String indexstr = a.getString(R.styleable.WorkLogEditItem_index);
		String contentstr = a.getString(R.styleable.WorkLogEditItem_content);
		String notestr = a.getString(R.styleable.WorkLogEditItem_note);
		boolean enabled = a.getBoolean(R.styleable.WorkLogEditItem_enable, false);
		content.setText(contentstr);
		note.setText(notestr);
		index.setText(indexstr);
		setEable(enabled);
		setGra(Gravity.CENTER);
		a.recycle();
	}

	private void setGra(int gravity) {
		content.setGravity(gravity);
		note.setGravity(gravity);
	}

	public void setBg(int res) {
		index.setBackgroundResource(res);
		content.setBackgroundResource(res);
		note.setBackgroundResource(res);
	}

	public void setTextStyleBlod(){
		index.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
		content.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
		note.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
	}

	public void setEable(boolean enabled) {
		content.setEnabled(enabled);
		note.setEnabled(enabled);
	}

	public void setValue(String contentStr, String noteStr) {
		content.setText(contentStr);
		note.setText(noteStr);
	}

	public String getContent() {
		return content.getText().toString();
	}

	public String getNote() {
		return note.getText().toString();
	}

}
